MySql wordpress 

How to replace WordPress site URL in Database – updated 2021

There might be many possibilities when you want to change the WordPress site URL.

  1. Completely moving your site from one domain name to another.
  2. when we want o to add HTTPS instead of HTTP which is migrating sight from HTTP to HTTPS.
  3. when you want to add www. to your site.

There are many ways we can solve this

Note: Before doing any of the following methods please back up your database once

Solution one – Replace WordPress site URL in Database

To Replace Open your PHPMyAdmin and select the database in which you want to replace it.
This is one of the good ways to solve the URL issues. To solve and replace the URL we will be using MySQL replace() function.

Note: if you do not have a PHPMyAdmin setup then you can go to your server root and access MySQL from there.

To replace the URL you need to run the SQL Query provided below.
Be careful about your database table name prefix ‘wp_’ there are possibilities that your table prefix might be different.
In Below SQL query replace old site URL and new site URL

UPDATE wp_options SET option_value = replace(option_value, 'Existing URL', 'New URL') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'Existing URL','New URL');

UPDATE wp_usermeta SET meta_value = replace(meta_value, 'Existing URL','New URL');

UPDATE wp_links SET link_url = replace(link_url, 'Existing URL','New URL');

UPDATE wp_comments SET comment_content = replace(comment_content , 'Existing URL','New URL');

If any URL you have used inside any post or pages or attachments then extend using the below code.

UPDATE wp_posts SET post_content = replace(post_content, 'Existing URL', 'New URL');

UPDATE wp_links SET link_image = replace(link_image, 'Existing URL','New URL');

UPDATE wp_posts SET guid = replace(guid, 'Existing URL','New URL');

Solution Two – Using WordPress plugins

If you are not confident using Database you can consider this solution

Also Read:  10 Must-Have WordPress Plugins For Bloggers With Webmaster Concerns

1. Search and Replace Plugin.

Note: This plugin is currently not maintained and Deprecated, so please try using a new plugin called – Better Search Replace

Install the plugin (click here to redirect) and navigate to setting -> click search and replace menu as shown below

First, replace the main domain name

To replace all the URLs in all the database tables.

Note: enter a search keyword, replace the keyword and then select tables to replace. before the final submit, check dry run to find weather all replace are correct or not. If all correct then uncheck dry run and re-run.

Related posts